package com.example.demo.controller;

import cn.hutool.core.util.StrUtil;
import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.example.demo.service.IUserService;

import javax.annotation.Resource;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserService userService;
    @PostMapping("/register")
    public int save(@RequestBody User user){
       return  userService.save(user);
    }

    @PostMapping("/login")
    public String login(@RequestBody User user){
        String username=user.getUsername();
        String password=user.getPassword();
        System.out.println("username="+username);
        System.out.println("password="+password);
        if(username.equals("")||password.equals("")){
            return "用户名或密码为空";
        }else {
            if(userMapper.login(username,password)!=null){
                return "登录成功";
            }
            else {
                return "登录失败";
            }
        }
    }

    @GetMapping
    public List<User> getUser(){
        List<User> list=userMapper.findAll();
        return  list;
    }


}
